package com.example.ljw.paperlive.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.ljw.paperlive.R;
import com.example.ljw.paperlive.bean.FamliyBean;
import com.example.ljw.paperlive.ui.famliy.LiveActivity;
import com.example.ljw.paperlive.utils.RecyclerViewAdapterHelper;
import com.example.ljw.paperlive.widget.GlideCircleTransform;

import java.util.List;

/**
 * Created by LJW on 2016/11/24.
 */

public class FamliyRecyclerDaylistAdapter extends RecyclerViewAdapterHelper<FamliyBean.ListBean> {
    public static final int TYPE1=1,TYPE2=2,TYPE3=3;

    public FamliyRecyclerDaylistAdapter(Context context, List<FamliyBean.ListBean> list) {
        super(context, list);
    }

    @Override
    public int getItemCount() {

        return mList!=null?mList.size():0;
    }

    @Override
    public int getItemViewType(int position) {
        if (position==0){
            return TYPE1;
        }else if(position==1){
            return TYPE2;
        }else{
            return TYPE3;
        }

    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view=null;
        switch (viewType){
            case TYPE1:
                view=mInflater.inflate(R.layout.item_famliy_one,parent,false);
                return new ViewHolder1(view);
            case TYPE2:
                view=mInflater.inflate(R.layout.item_famliy_two,parent,false);
                return new ViewHolder2(view);
            case TYPE3:
                view=mInflater.inflate(R.layout.item_famliy_three,parent,false);
                return new ViewHolder3(view);

        }
       return null;
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        //one
//        String imghead=mList.get(0).getAvatar();
//        String name =mList.get(0).getName();
//        String introduce=mList.get(0).getSlogan();

//        String img_left=mList.get(0).getLivelist().get(0).getCover();
//        String img_right1=mList.get(0).getLivelist().get(1).getCover();
//        String img_right2=mList.get(0).getLivelist().get(2).getCover();
        if(holder instanceof ViewHolder1){
            ViewHolder1 holder1= (ViewHolder1) holder;
            //头像
            Glide.with(mContext)
                    .load(mList.get(position).getAvatar())
                    .transform(new GlideCircleTransform(mContext))
//                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder1.img_famliy_name_one);
            //名字
            holder1.tv_famliy_name_one.setText(mList.get(position).getName());
            holder1.tv_famliy_peopleleftname_one.setText(mList.get(position).getLivelist().get(0).getUser().getNickname());
            holder1.tv_famliy_peopleright1name_one.setText(mList.get(position).getLivelist().get(1).getUser().getNickname());
            if (mList.get(position).getLivelist().size()>=3){
                holder1.tv_famliy_peopleright2name_one.setText(mList.get(position).getLivelist().get(2).getUser().getNickname());
                //            左边图2
                Glide.with(mContext)
                        .load(mList.get(position).getLivelist().get(2).getCover())
                        .centerCrop()//这个会影响trasform
                        .placeholder(R.mipmap.ic_launcher)
                        .into(holder1.img_famliy_right2_one);
            }
            Log.e("position","++++++++++++++"+mList.get(0).getLivelist().size());

            //介绍
            holder1.tv_famliy_introduce_one.setText(mList.get(position).getSlogan());
            //左边图
            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(0).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder1.img_famliy_left_one);
            //左边图1
            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(1).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder1.img_famliy_right1_one);


        }else if(holder instanceof  ViewHolder2){
            ViewHolder2 holder2= (ViewHolder2) holder;
            //头像
            Glide.with(mContext)
                    .load(mList.get(position).getAvatar())
                    .transform(new GlideCircleTransform(mContext))
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder2.img_famliy_name_two);
            //名字
            holder2.tv_famliy_name_two.setText(mList.get(position).getName());
            holder2.tv_famliy_peopleleftname_two.setText(mList.get(position).getLivelist().get(0).getUser().getNickname());
            if(mList.get(1).getLivelist().get(1).getUser()==null){
            }else {
                holder2.tv_famliy_peoplerightname_two.setText(mList.get(1).getLivelist().get(1).getUser().getNickname());

            }
            //介绍
            holder2.tv_famliy_introduce_two.setText(mList.get(position).getSlogan());
            //左边图
            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(0).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder2.img_famliy_left_two);
            //右边图
            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(1).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder2.img_famliy_right_two);

        }else if(holder instanceof ViewHolder3){
            ViewHolder3 holder3= (ViewHolder3) holder;
            //名次
            holder3.tv_famliy_rank_three.setText("0"+(position+1));
            //头像
            Glide.with(mContext)
                    .load(mList.get(position).getAvatar())
                    .transform(new GlideCircleTransform(mContext))
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder3.img_famliy_name_three);
            //名字
            holder3.tv_famliy_name_three.setText(mList.get(position).getName());

            //介绍
            holder3.tv_famliy_introduce_three.setText(mList.get(position).getSlogan());
            //3个图
            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(0).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder3.img_famliy_left1_three);

            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(1).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder3.img_famliy_left2_three);

            Glide.with(mContext)
                    .load(mList.get(position).getLivelist().get(2).getCover())
                    .centerCrop()//这个会影响trasform
                    .placeholder(R.mipmap.ic_launcher)
                    .into(holder3.img_famliy_left3_three);


        }


    }
    public class ViewHolder1 extends RecyclerView.ViewHolder implements View.OnClickListener{
        private ImageView img_famliy_name_one;
        private TextView tv_famliy_name_one;
        private TextView tv_famliy_introduce_one;
        private ImageView img_famliy_left_one;
        private ImageView img_famliy_right1_one;
        private ImageView img_famliy_right2_one;
        private TextView tv_famliy_peopleleftname_one;
        private TextView tv_famliy_peopleright1name_one;
        private TextView tv_famliy_peopleright2name_one;
        private LinearLayout layout_famliy_one;



        public ViewHolder1(View itemView) {
            super(itemView);
            //实例化控件
            intiview(itemView);
        }

        private void intiview(View itemView) {
            img_famliy_name_one= (ImageView) itemView.findViewById(R.id.img_famliy_name_one);
            tv_famliy_name_one= (TextView) itemView.findViewById(R.id.tv_famliy_name_one);
            tv_famliy_introduce_one= (TextView) itemView.findViewById(R.id.tv_famliy_introduce_one);
            img_famliy_left_one= (ImageView) itemView.findViewById(R.id.img_famliy_left_one);
            img_famliy_right1_one= (ImageView) itemView.findViewById(R.id.img_famliy_right1_one);
            img_famliy_right2_one= (ImageView) itemView.findViewById(R.id.img_famliy_right2_one);
            tv_famliy_peopleleftname_one= (TextView) itemView.findViewById(R.id.tv_famliy_peopleleftname_one);
            tv_famliy_peopleright1name_one= (TextView) itemView.findViewById(R.id.tv_famliy_peopleright1name_one);
            tv_famliy_peopleright2name_one= (TextView) itemView.findViewById(R.id.tv_famliy_peopleright2name_one);
            layout_famliy_one= (LinearLayout) itemView.findViewById(R.id.layout_famliy_one);
            //监听
            layout_famliy_one.setOnClickListener(this);
            img_famliy_left_one.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            Intent intent=null;
            switch (view.getId()){
                case R.id.layout_famliy_one:
                    break;
                case R.id.img_famliy_left_one:
                    intent=new Intent(mContext, LiveActivity.class);
                    intent.putExtra("URL",mList.get(0).getLivelist().get(getAdapterPosition()).getHtmlShare());
                    mContext.startActivity(intent);
                    break;
                case R.id.img_famliy_right1_one:
                    break;
                case R.id.img_famliy_right2_one:
                    break;

            }

        }
    }
    public class ViewHolder2 extends RecyclerView.ViewHolder{
        private ImageView img_famliy_name_two;
        private TextView  tv_famliy_name_two;
        private TextView  tv_famliy_introduce_two;
        private ImageView img_famliy_left_two;
        private ImageView img_famliy_right_two;
        private TextView  tv_famliy_peopleleftname_two;
        private TextView  tv_famliy_peoplerightname_two;



        public ViewHolder2(View itemView) {
            super(itemView);
            img_famliy_name_two= (ImageView) itemView.findViewById(R.id.img_famliy_name_two);
            tv_famliy_name_two= (TextView) itemView.findViewById(R.id.tv_famliy_name_two);
            tv_famliy_introduce_two= (TextView) itemView.findViewById(R.id.tv_famliy_introduce_two);
            img_famliy_left_two= (ImageView) itemView.findViewById(R.id.img_famliy_left_two);
            img_famliy_right_two= (ImageView) itemView.findViewById(R.id.img_famliy_right_two);
            tv_famliy_peopleleftname_two= (TextView) itemView.findViewById(R.id.tv_famliy_peopleleftname_two);
            tv_famliy_peoplerightname_two= (TextView) itemView.findViewById(R.id.tv_famliy_peoplerightname_two);
        }
    }
    public class ViewHolder3 extends RecyclerView.ViewHolder{
        private ImageView img_famliy_name_three;
        private TextView  tv_famliy_name_three;
        private TextView  tv_famliy_introduce_three;
        private ImageView img_famliy_left1_three;
        private ImageView img_famliy_left2_three;
        private ImageView img_famliy_left3_three;
        private TextView  tv_famliy_rank_three;

        public ViewHolder3(View itemView) {
            super(itemView);
            img_famliy_name_three= (ImageView) itemView.findViewById(R.id.img_famliy_name_three);
            tv_famliy_name_three= (TextView) itemView.findViewById(R.id.tv_famliy_name_three);
            tv_famliy_introduce_three= (TextView) itemView.findViewById(R.id.tv_famliy_introduce_three);
            img_famliy_left1_three= (ImageView) itemView.findViewById(R.id.img_famliy_left1_three);
            img_famliy_left2_three= (ImageView) itemView.findViewById(R.id.img_famliy_left2_three);
            img_famliy_left3_three= (ImageView) itemView.findViewById(R.id.img_famliy_left3_three);
            tv_famliy_rank_three= (TextView) itemView.findViewById(R.id.tv_famliy_rank_three);

        }
    }
}
